package com.chinasoft04.mall.mapper;

import com.chinasoft04.mall.pojo.AuthRolePojo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SpManagerAndRoleMapper {

    @Select("SELECT ps_ids FROM sp_manager as a, sp_role as b WHERE a.mg_id = #{mg_id} AND a.role_id = b.role_id")
    String getPsIdsByMgId(Integer mg_id);

    @Select("SELECT * FROM sp_role")
    List<AuthRolePojo> getAllRole();

    @Insert("INSERT INTO sp_role(role_name, role_desc) value(#{role_name}, #{role_desc})")
    Integer addRole(AuthRolePojo rolePojo);

    @Select("SELECT * FROM sp_role WHERE role_id = #{id}")
    AuthRolePojo getRoleByRoleId(Integer id);

    @Update("UPDATE sp_role SET role_name = #{role_name}, role_desc = #{role_desc} WHERE role_id = #{role_id}")
    int updateRoleByRoleId(AuthRolePojo rolePojo);

    @Delete("DELETE FROM sp_role WHERE role_id = #{role_id}")
    int deleteRoleByRoleId(Integer id);

    @Update("UPDATE sp_role SET ps_ids = #{rids} WHERE role_id = #{roleId}")
    int replaceAuthByRidsAndRoleId(Integer roleId, String rids);
}
